package com.groupbuying.cheetah.order.orderManagement.controller;

import com.groupbuying.cheetah.order.orderManagement.service.OrderService;
import com.groupbuying.cheetah.utils.apiresult.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/ushop")
public class OrderController {

    @Autowired
    private OrderService orderService;


    /**
     * 通过订单号获取收银台ID
     *
     * @param orderId 订单ID
     */
    @GetMapping("/getCounterIdByOrderId")
    public String getCounterIdByOrderId(String orderId) {
        System.out.println("订单Id"+orderId);
        return orderService.get(orderId).getCounterId();
    }

    /**
     * 小程序通过订单id获取订单时间
     */
    @PostMapping("/getDataByIdForOrder")
    public ApiResult getDataByIdForOrder(@RequestParam Map<String, Object> map) {
        Object time = map.get("startTime");
        if (time == null) {
            return orderService.getOrderByCountId(map);
        } else {
            return orderService.getDataByCustomer(map);
        }
    }

    /**
     * 根据时间查询
     */
    @PostMapping("/getOrderByGmtTimeForOrder")
    public ApiResult getOrderByGmtTimeForOrder(@RequestParam Map<String, Object> map) {
        return orderService.getOrderByGmtTime(map);
    }

    /**
     * 获取当日订单
     */
    @PostMapping("/getTodayOrder")
    public ApiResult getTodayOrder(@RequestParam Map<String, Object> map) {
        return orderService.getTodayOrder(map);
    }

    @PostMapping("/countOrder")
    public ApiResult countOrder(@RequestParam Map<String, Object> map) {
        return orderService.countOrder(map);
    }

}
